//
//  HZWuDangAndPanKouView.m
//  HZTC_Stock
//
//  Created by MayerF on 17/3/14.
//  Copyright © 2017年 MayerF. All rights reserved.
//

#import "HZWuDangAndPanKouView.h"
#import "MYRadioGroup.h"
#import "HZWuDangView.h"
#import "HZPanKouView.h"
#import "HZMingXiView.h"

#define kMenuH 30
#define kContentH 120

@interface HZWuDangAndPanKouView()
{
    //缓存下数据
    HZMinPriceModel *_pMinPriceModel;
    NSArray *_mingxiCache;
}
@property (nonatomic, strong)MYRadioGroup  *pRadioGroup;
@property (nonatomic, strong)HZWuDangView  *pWuDangView;
@property (nonatomic, strong)HZPanKouView  *pPanKouView;
@property (nonatomic, strong)HZMingXiView  *pMingXiView;

@property (nonatomic, strong)UIView *pLine1;
@property (nonatomic, strong)UIView *pLine2;
@end

@implementation HZWuDangAndPanKouView

#pragma mark -
#pragma mark 生命周期
- (instancetype)init{
    self = [super init];
    if (self) {
        [self p_commonInit];
        self.backgroundColor = [HZCommonTool getThemeColor];
    }
    return self;
}
#pragma mark -
#pragma mark private
- (void)p_commonInit
{
    _pLine1 = [UIView new];
    _pLine2 = [UIView new];
    _pRadioGroup = [MYRadioGroup new];
    _pRadioGroup.parent = self;
    _pRadioGroup.backgroundColor = [HZCommonTool getThemeColor];
    NSArray *titleArray = [NSArray arrayWithObjects:@"五档",@"盘口",@"明细", nil];
    [_pRadioGroup setRadioGroup:titleArray];
    [_pRadioGroup setHiddenSeparateLine:YES andHiddenUnderline:NO];
    [_pRadioGroup setSelectedButton:0];
    [_pRadioGroup resetAllButtonFont:[UIFont systemFontOfSize:15]];
    [_pRadioGroup resetUnderLineWidth:50 isReset:YES];
    
    _pWuDangView = [HZWuDangView new];
    
    [self addSubview:_pRadioGroup];
    [self addSubview:_pWuDangView];
    [self addSubview:_pLine1];
    [self addSubview:_pLine2];
    
    _pLine1.backgroundColor = _pLine2.backgroundColor = [HZCommonTool getThemeSeperateColorWithDefaultColor:nil];
    
    [self p_initConstraints];
}

- (void)p_initConstraints
{
    [_pRadioGroup mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self);
        make.left.mas_equalTo(self);
        make.right.mas_equalTo(self);
        make.height.mas_equalTo(kMenuH);
    }];
    [_pWuDangView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_pRadioGroup.mas_bottom);
        make.left.mas_equalTo(self);
        make.right.mas_equalTo(self);
        make.bottom.mas_equalTo(self);
    }];
    
    [_pLine1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.mas_equalTo(self);
        make.height.mas_equalTo(0.5);
    }];
    [_pLine2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self);
        make.bottom.mas_equalTo(_pRadioGroup.mas_bottom);
        make.height.mas_equalTo(0.5);
    }];
}

- (void)p_loadPanKouView
{
    if (!_pPanKouView) {
        _pPanKouView = [HZPanKouView new];
        [self addSubview:_pPanKouView];
    }
    [_pPanKouView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_pRadioGroup.mas_bottom);
        make.left.mas_equalTo(self);
        make.right.mas_equalTo(self);
//        make.height.mas_equalTo(kContentH);
        make.bottom.mas_equalTo(self);
    }];
    [self bringSubviewToFront:_pPanKouView];
}
- (UIView *)p_loadMingXiView
{
    if (!_pMingXiView) {
        _pMingXiView = [HZMingXiView new];
        _pMingXiView.parent = self;
        [self addSubview:_pMingXiView];
        [_pMingXiView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(_pRadioGroup.mas_bottom);
            make.left.mas_equalTo(self);
            make.right.mas_equalTo(self);
            make.bottom.mas_equalTo(self);
        }];
    }
    [self bringSubviewToFront:_pMingXiView];
    return _pMingXiView;
}


- (void)p_showRelatedView:(NSString *)title
{
    [self sendSubviewToBack:_pPanKouView];
    [self sendSubviewToBack:_pMingXiView];
    if ([title isEqual:kHZPanKou]) {
        [self p_loadPanKouView];
        [_pPanKouView updateNewData:_pMinPriceModel];
    }else if ([title isEqual:kHZMingXi]) {
        [self p_loadMingXiView];
        [_pMingXiView updateNewData:_mingxiCache];
    }
}
#pragma mark -
#pragma mark public
- (void)updateNewData:(HZMinPriceModel *)data
{
    _pMinPriceModel = data;
    [_pWuDangView updateNewData:data];
    [_pPanKouView updateNewData:data];
}
- (void)updateDetialData:(NSArray *)data
{
    _mingxiCache = data;
    [_pMingXiView updateNewData:data];
}
#pragma mark -
- (void)upToParentWithObjc:(id)objc withType:(NSInteger)type withParamter:(id)paramter{
    switch (type) {
        case kHZ_radioGroupClick_Action:
        {
            if ([paramter isKindOfClass:[UIButton class]]) {
                UIButton *btn = (UIButton *)paramter;
                [self p_showRelatedView:btn.currentTitle];
            }
        }
            break;
            
        default:
            break;
    }
}
- (void)downToChildWithObjc:(id)objc withType:(NSInteger)type withParamter:(id)paramter{
}

@end
